
<h1><span class="yiyi-st" id="yiyi-13">numpy.random.RandomState.random_sample</span></h1>
        <blockquote>
        <p>原文：<a href="https://docs.scipy.org/doc/numpy/reference/generated/numpy.random.RandomState.random_sample.html">https://docs.scipy.org/doc/numpy/reference/generated/numpy.random.RandomState.random_sample.html</a></p>
        <p>译者：<a href="https://github.com/wizardforcel">飞龙</a> <a href="http://usyiyi.cn/">UsyiyiCN</a></p>
        <p>校对：（虚位以待）</p>
        </blockquote>
    
<dl class="method">
<dt id="numpy.random.RandomState.random_sample"><span class="yiyi-st" id="yiyi-14"> <code class="descclassname">RandomState.</code><code class="descname">random_sample</code><span class="sig-paren">(</span><em>size=None</em><span class="sig-paren">)</span></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-15">在半开间隔[0.0，1.0]中返回随机浮点数。</span></p>
<p><span class="yiyi-st" id="yiyi-16">结果来自在所述间隔上的“连续均匀”分布。</span><span class="yiyi-st" id="yiyi-17">要对<img alt="Unif[a, b), b &gt; a" class="math" src="../../_images/math/e9a05a99f961e8f094b3869fcddd366857d7b0d9.png" style="vertical-align: -4px">乘以<a class="reference internal" href="numpy.random.random_sample.html#numpy.random.random_sample" title="numpy.random.random_sample"><code class="xref py py-obj docutils literal"><span class="pre">random_sample</span></code></a>的输出乘以<em class="xref py py-obj">（b-a）</em>并添加<em class="xref py py-obj">a</em></span></p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="p">(</span><span class="n">b</span> <span class="o">-</span> <span class="n">a</span><span class="p">)</span> <span class="o">*</span> <span class="n">random_sample</span><span class="p">()</span> <span class="o">+</span> <span class="n">a</span>
</pre></div>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name">
<col class="field-body">
<tbody valign="top">
<tr class="field-odd field"><th class="field-name"><span class="yiyi-st" id="yiyi-18">参数：</span></th><td class="field-body"><p class="first"><span class="yiyi-st" id="yiyi-19"><strong>size</strong>：int或tuple的整数，可选</span></p>
<blockquote>
<div><p><span class="yiyi-st" id="yiyi-20">输出形状。</span><span class="yiyi-st" id="yiyi-21">如果给定形状是例如<code class="docutils literal"><span class="pre">（m，</span> <span class="pre">n，</span> <span class="pre">k）</span></code>，则<code class="docutils literal"><span class="pre"> m</span> <span class="pre">*</span> <span class="pre">n</span> <span class="pre">*</span> <span class="pre">k</span></code></span><span class="yiyi-st" id="yiyi-22">默认值为None，在这种情况下返回单个值。</span></p>
</div></blockquote>
</td>
</tr>
<tr class="field-even field"><th class="field-name"><span class="yiyi-st" id="yiyi-23">返回：</span></th><td class="field-body"><p class="first"><span class="yiyi-st" id="yiyi-24"><strong>out</strong>：float或ndarray的浮点数</span></p>
<blockquote class="last">
<div><p><span class="yiyi-st" id="yiyi-25">形状<em class="xref py py-obj">大小</em>的随机浮点数组（除非<code class="docutils literal"><span class="pre">size=None</span></code>，在这种情况下返回单个浮点数）。</span></p>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
<p class="rubric"><span class="yiyi-st" id="yiyi-26">例子</span></p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">random_sample</span><span class="p">()</span>
<span class="go">0.47108547995356098</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">type</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">random_sample</span><span class="p">())</span>
<span class="go">&lt;type &apos;float&apos;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">random_sample</span><span class="p">((</span><span class="mi">5</span><span class="p">,))</span>
<span class="go">array([ 0.30220482,  0.86820401,  0.1654503 ,  0.11659149,  0.54323428])</span>
</pre></div>
</div>
<p><span class="yiyi-st" id="yiyi-27">来自[-5,0）的随机数的3&#xD7;2数组：</span></p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="mi">5</span> <span class="o">*</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">random_sample</span><span class="p">((</span><span class="mi">3</span><span class="p">,</span> <span class="mi">2</span><span class="p">))</span> <span class="o">-</span> <span class="mi">5</span>
<span class="go">array([[-3.99149989, -0.52338984],</span>
<span class="go">       [-2.99091858, -0.79479508],</span>
<span class="go">       [-1.23204345, -1.75224494]])</span>
</pre></div>
</div>
</dd></dl>
